package com.wisdomstar.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wisdomstar.common.utils.StringUtils;
import com.wisdomstar.system.domain.SysOperLog;
import com.wisdomstar.system.mapper.SysOperLogMapper;
import com.wisdomstar.system.service.ISysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 操作日志 服务层处理
 * 
 * @author RinMi
 */
@Service
public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOperLog> implements ISysOperLogService
{
    private final SysOperLogMapper operLogMapper;
    @Autowired
    public SysOperLogServiceImpl(SysOperLogMapper operLogMapper) {
        this.operLogMapper = operLogMapper;
    }

    /**
     * 新增操作日志
     * 
     * @param operLog 操作日志对象
     */
    @Override
    public void insertOperlog(SysOperLog operLog)
    {
        operLogMapper.insert(operLog);
    }

    /**
     * 查询系统操作日志集合
     * 
     * @param operLog 操作日志对象
     * @return 操作日志集合
     */
    @Override
    public List<SysOperLog> selectOperLogList(SysOperLog operLog)
    {
        LambdaQueryWrapper<SysOperLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(operLog.getTitle()), SysOperLog::getTitle, operLog.getTitle());
        queryWrapper.eq(StringUtils.isNotNull(operLog.getBusinessType()),SysOperLog::getBusinessType, operLog.getBusinessType());
        queryWrapper.in(StringUtils.isNotEmpty(operLog.getBusinessTypes()),SysOperLog::getBusinessTypes, (Object) operLog.getBusinessTypes());
        queryWrapper.eq(StringUtils.isNotNull(operLog.getStatus()), SysOperLog::getStatus, operLog.getStatus());
        queryWrapper.like(StringUtils.isNotNull(operLog.getOperName()), SysOperLog::getOperName, operLog.getOperName());
        queryWrapper.ge(StringUtils.isNotNull(operLog.getParams().get("beginTime")), SysOperLog::getOperTime, operLog.getParams().get("beginTime"));
        queryWrapper.le(StringUtils.isNotNull(operLog.getParams().get("endTime")), SysOperLog::getOperTime, operLog.getParams().get("endTime"));
        queryWrapper.orderByDesc(SysOperLog::getOperId);
        return operLogMapper.selectList(queryWrapper);
    }

    /**
     * 批量删除系统操作日志
     * 
     * @param operIds 需要删除的操作日志ID
     * @return 结果
     */
    @Override
    public int deleteOperLogByIds(Long[] operIds)
    {
        return operLogMapper.deleteBatchIds(Arrays.asList(operIds));
    }

    /**
     * 查询操作日志详细
     * 
     * @param operId 操作ID
     * @return 操作日志对象
     */
    @Override
    public SysOperLog selectOperLogById(Long operId)
    {
        return operLogMapper.selectById(operId);
    }

    /**
     * 清空操作日志
     */
    @Override
    public void cleanOperLog()
    {
        operLogMapper.cleanOperLog();
    }
}
